/*
 * Copyright (C) 2012, EADS France
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.utils;
import java.io.IOException;
import java.io.InputStream;


/**
 *
 * @author Laurent WOUTERS
 */
class CompositeInputStream extends InputStream {
    private int[] buffer;
    private InputStream stream;
    private int index;
    
    public CompositeInputStream(int[] buffer, InputStream stream) {
        this.buffer = buffer;
        this.stream = stream;
    }

    @Override public int read() throws IOException {
        if (index >= buffer.length) return stream.read();
        int value = buffer[index];
        index++;
        if (value != 0) return value;
        return stream.read();
    }
}
